package com.example.wwww.controller;

import com.example.wwww.model.RiderLocation;
import com.example.wwww.repo.InMemoryStore;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/rider-locations")
public class RiderLocationController {
    private final InMemoryStore store;
    public RiderLocationController(InMemoryStore store) { this.store = store; }

    @GetMapping
    public List<RiderLocation> list(@RequestParam(value = "active", required = false) Boolean active) {
        return (active != null && active) ? store.getActiveRiderLocations() : store.getRiderLocations();
    }

    @PostMapping
    public RiderLocation create(@RequestBody RiderLocation data) { return store.addRiderLocation(data); }
}


